package com.example.thegreatwall.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashMap;

@RestController
@CrossOrigin
public class UserMysocketController {
    @GetMapping(value = "/returnsocket")
    public String returnsocket(String userId) throws IOException {
        System.out.println(userId);
        //通过websocket推送到小程序端
        HashMap<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("message","当前账号被封禁,有需要请联系管理员！");
        String json=new ObjectMapper().writeValueAsString(map);
        MyWebSocket.webSocketMap.get(userId).getBasicRemote().sendText(json);
        return "ok";
    }
}
